<template>
<a-modal :maskClosable="false"
        :title="title"
        :width="800"
        :visible="visible"
        :confirmLoading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
        cancelText="关闭">

<a-spin :spinning="confirmLoading">
   <a-form-model ref="form"  v-bind="layout"  :model="model" :rules="validatorRules">

      <a-form-model-item label="主键ID"  prop="id">
           <a-input placeholder="请输入主键ID"  v-model="model.id"  />
        </a-form-model-item >
      <a-form-model-item label="创建时间" required prop="createTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.createTime"  />
        </a-form-model-item >
      <a-form-model-item label="编辑时间" required prop="updateTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.updateTime"  />
        </a-form-model-item >
      <a-form-model-item label="项目编码唯 一" required prop="projectCode">
           <a-input placeholder="请输入项目编码唯 一"  v-model="model.projectCode"  />
        </a-form-model-item >
      <a-form-model-item label="单品名称" required prop="projectName">
           <a-input placeholder="请输入单品名称"  v-model="model.projectName"  />
        </a-form-model-item >
      <a-form-model-item label="项目ID. 取door_service_project，有可能是空的" required prop="projectId">
           <a-input placeholder="请输入项目ID. 取door_service_project，有可能是空的"  v-model="model.projectId"  />
        </a-form-model-item >
      <a-form-model-item label="服务内容" required prop="content">
           <a-input placeholder="请输入服务内容"  v-model="model.content"  />
        </a-form-model-item >
      <a-form-model-item label="项目费用" required prop="amount">
           <a-input placeholder="请输入项目费用"  v-model="model.amount"  />
        </a-form-model-item >
      <a-form-model-item label="服务要求" required prop="serviceRequirement">
           <a-input placeholder="请输入服务要求"  v-model="model.serviceRequirement"  />
        </a-form-model-item >
      <a-form-model-item label="服务计划" required prop="servicePlan">
           <a-input placeholder="请输入服务计划"  v-model="model.servicePlan"  />
        </a-form-model-item >
      <a-form-model-item label="服务描述大文本" required prop="description">
           <a-input placeholder="请输入服务描述大文本"  v-model="model.description"  />
        </a-form-model-item >
      <a-form-model-item label="描述"  prop="remark">
           <a-input placeholder="请输入描述"  v-model="model.remark"  />
        </a-form-model-item >
      <a-form-model-item label="服务人员角色，1护士 2护工 3医生 4社工 5其他" required prop="opRole">
           <a-input placeholder="请输入服务人员角色，1护士 2护工 3医生 4社工 5其他"  v-model="model.opRole"  />
        </a-form-model-item >
      <a-form-model-item label="医院机构编码" required prop="orgCode">
           <a-input placeholder="请输入医院机构编码"  v-model="model.orgCode"  />
        </a-form-model-item >
      <a-form-model-item label="租户id" required prop="tenantId">
           <a-input placeholder="请输入租户id"  v-model="model.tenantId"  />
        </a-form-model-item >
      </a-form-model>
    </a-spin>
</a-modal>
</template>

<script>
  import { httpAction,putAction,getAction,postAction} from '@api/manage'

  export default {
    name: "hChDoorProjectPackageDetailModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        layout: {
           labelCol: { span: 4 },
           wrapperCol: { span: 14 },
        },
        confirmLoading: false,
        validatorRules:{
        createTime:[{ required: true, message: '请输入创建时间!' }],
        updateTime:[{ required: true, message: '请输入编辑时间!' }],
        projectCode:[{ required: true, message: '请输入项目编码唯 一!' }],
        projectName:[{ required: true, message: '请输入单品名称!' }],
        projectId:[{ required: true, message: '请输入项目ID. 取door_service_project，有可能是空的!' }],
        content:[{ required: true, message: '请输入服务内容!' }],
        amount:[{ required: true, message: '请输入项目费用!' }],
        serviceRequirement:[{ required: true, message: '请输入服务要求!' }],
        servicePlan:[{ required: true, message: '请输入服务计划!' }],
        description:[{ required: true, message: '请输入服务描述大文本!' }],
        opRole:[{ required: true, message: '请输入服务人员角色，1护士 2护工 3医生 4社工 5其他!' }],
        orgCode:[{ required: true, message: '请输入医院机构编码!' }],
        tenantId:[{ required: true, message: '请输入租户id!' }],
        },
        url: {
          add: "/system/hChDoorProjectPackageDetail",
          edit: "/system/hChDoorProjectPackageDetail",
        },
      }
    },
    created () {
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
          this.model = Object.assign({}, record);
          this.visible = true;
      },
      close () {
          this.$refs.form.clearValidate();
          this.$emit('close');
          this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                 that.$message.success(res.message);
                 that.$emit('ok');
              }else{
                 that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
            return false;
         }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>